package fs;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URISyntaxException;
import java.net.URL;

/**
 *
 * @author lucifer
 */
public class Data {

  // home
  public static final String HOME  = System.getProperty("user.home");
  public static final String SLASH = File.separator;
  public static final String SENZU_PATH = HOME + SLASH + "Senzu";

  public static final String SENZU_MAN = SENZU_PATH + SLASH + SLASH + "manual.pdf";
  //public static final String SENZU_INSTALL = SENZU_PATH + SLASH + "doc" + SLASH + "install.pdf";

  //public static final String SENZU_REPORTS = SENZU_PATH + SLASH + "Reportes";
  //public static final String TURNO_COMPROBANTE = SENZU_REPORTS + "TurnoComprobante.pdf";
  //public static final String TURNO_ASISTENCIA = SENZU_REPORTS + "TurnoAsistencia.pdf";
  //public static final String LIQUIDACION_PARTICULARES = SENZU_REPORTS + "LiquidacionParticulares"; // + date + ".pdf"
  //public static final String LIQUIDACION_OBRA_SOCIAL = SENZU_REPORTS + "LiquidacionObraSocial"; // + obraSocialID + "-" + date + ".pdf"

  // conf
  public static final String SENZU_CONF = SENZU_PATH + SLASH + ".conf";
  public static final String DB_SETTINGS = SENZU_CONF + SLASH + "db.conf";
  public static final String EMAIL_SETTINGS = SENZU_CONF + SLASH + "email.conf";
  public static final String LOOK_AND_FEEL_FILE = SENZU_CONF + SLASH + "laf.conf";
  public static final String PREVIEW_COMPROBANTES = SENZU_CONF + SLASH + "preview.conf";
  public static final String TOOLBAR_FILE = SENZU_PATH + SLASH + "tb.conf";

  // reports
  public static final String SENZU_LIQUIDACIONES = SENZU_PATH + SLASH + "Liquidaciones";
  public static final String SENZU_COMPROBANTES = SENZU_PATH + SLASH + "Comprobantes";

  public static void WriteObjectTo(Object anObject, String filename) throws Exception {
    new File(SENZU_PATH).mkdirs();
    new File(SENZU_CONF).mkdirs();
    new File(SENZU_LIQUIDACIONES).mkdirs();
    new File(SENZU_COMPROBANTES).mkdirs();

    FileOutputStream f = new FileOutputStream(filename);
    ObjectOutputStream out = new ObjectOutputStream(f);
    out.writeObject(anObject);
    f.close();
  }

  /* not needed
  public static void writeObjectOn(Object anObject, File file) throws Exception {
    FileOutputStream f = new FileOutputStream(file);
    ObjectOutputStream out = new ObjectOutputStream(f);
    out.writeObject(anObject);
    f.close();
  }
  */

  public static Object ReadFrom(String filename) throws Exception {
    FileInputStream f = new FileInputStream(filename);
    ObjectInputStream in = new ObjectInputStream(f);
    Object o = in.readObject();
    f.close();
    return o;
  }

  /* not needed
  public static Object readFrom(File file) throws Exception {
    FileInputStream f = new FileInputStream(file);
    ObjectInputStream in = new ObjectInputStream(f);
    Object o = in.readObject();
    f.close();
    return o;
  }
  */

  public static void CP(URL source, String destiny) throws URISyntaxException, FileNotFoundException, IOException {
    File f = new File(source.toURI());

    FileInputStream in = new FileInputStream(f);
    FileOutputStream out = new FileOutputStream(destiny);

    int b;
    while ((b = in.read()) != -1) {
      out.write(b);
    }
    out.close();
    in.close();
  }

}
